home *** CD-ROM | disk | FTP | other *** search
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; columnout - Library for outputing data in columns.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;
- ;;; Copyright (c) 1996 Harvey J. Stein <abel@netvision.net.il>, and
- ;;; eventually <hjstein@netvision.net.il>
- ;;; All Rights Reserved.
- ;;;
- ;;; This package is covered by the GNU GPL. You can freely use and
- ;;; distribute it as long as it stays under the GNU GPL, and as long as
- ;;; you distribute all the corresponding source code, and as long as this
- ;;; message and the above copyright notice remains.
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Columns of output
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define (write-list-in-cols
- lst item-format-fcn group-preamble line-preamble separator final-separator ncols)
- "Writes out LST in columns using specified ITEM-FORMAT-FCN on each
- item. The output is proceeded by GROUP-PREAMBLE. Each line is
- proceeded by LINE-PREAMBLE. Items are separated by SEPARATOR. The
- last item is followed by FINAL-SEPARATOR. NCOLS of items are placed
- on each line."
- (define (write-list-in-cols-aux lst list-len count)
- (cond ((= list-len 0))
- (else
- (cond ((= (modulo count ncols) 0)
- (format #t "\n")
- (format #t "~a" line-preamble)))
- (item-format-fcn (car lst))
- (if (= list-len 1)
- (format #t "~a" final-separator)
- (format #t "~a" separator))
- (write-list-in-cols-aux (cdr lst) (- list-len 1) (+ count 1)))))
- (format #t "~a" group-preamble)
- (write-list-in-cols-aux lst (length lst) 0))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Output which doesn't exceed a certain number of columns per line.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define (format-multiline col-wid line-cont-pref s . args)
- "Returns (format #f s args), except will break lines before arguments if
- the line gets too long. Too long is > COL-WID characters. Whenever a line
- gets broken, LINE-CONT-PREF is prepended to the next line."
- (define (format-aux chars flist alist)
- (let ((next-hunk (if (or (null? alist) (null? flist))
- ""
- (format #f (car flist) (car alist)))))
- (set! chars (+ chars (string-length next-hunk)))
- (cond ((> chars col-wid)
- (set! chars (+ (string-length line-cont-pref) (string-length next-hunk)))
- (set! next-hunk (string-append "\n" line-cont-pref next-hunk))))
- (if (or (null? alist) (null? flist))
- (list next-hunk)
- (cons next-hunk
- (format-aux chars (cdr flist) (cdr alist))))))
-
- (let* ((arg-len (length args))
- (matcher (string->regexp
- (string-append
- "^([^~]*)"
- (apply string-append (vector->list
- (make-vector arg-len
- "(~.?[^~]*)")))
- "$")))
- (match-list (matcher s))
- (flist (map (lambda (x) (apply substring s x))
- (cdr match-list))))
- (apply string-append
- (cons (car flist)
- (format-aux (string-length (car flist))
- (cdr flist) args)))))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Writing a list of items in fortran compatible format.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define (write-ftn-list lst write-fcn ncols)
- "Writes out LST of items in a FORTRAN format (lines start with
- a continuation character in the proper column, items are separated by
- commas, etc., NCOLS items per row."
- (write-list-in-cols lst write-fcn "" " + " "," "" ncols))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Output with fortran line breaks if necessary.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (define (format-fortran p s . args)
- "Returns (format p s args), except will break lines at arguments if
- the line gets too long. Too long is > 72 characters. Whenever a line
- gets broken, " + " is prepended to the next line."
- (apply format-fortran-w-cont p s " + " args))
-
- (define (format-fortran-w-cont p s cont . args)
- "Returns (format p s args), except will break lines at arguments if
- the line gets too long. Too long is > 72 characters. Whenever a line
- gets broken, " + " is prepended to the next line."
- (format p "~a" (apply format-multiline 72 cont s args)))
-
- (provide "columnout")
-